﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace blackhouse.BlackApart.Business.Prices {
    public class TimeToReservationPriceModifier : ApartmentPriceModifier {

        #region Fields

        private double modifiedPrice;
        private bool isApplicable = false;

        #endregion

        #region Methods

        public override void Prepare() {
            this.modifiedPrice = this.InitialPrice;
            int timeToReservation = (int) Math.Floor(( this.ReservationFromDay - DateTime.Now ).TotalHours);
            if (timeToReservation >= this.ModificationFromVariable && timeToReservation <= this.ModificationToVariable) {
                this.modifiedPrice = this.GetModifiedPrice(this.ModificationType, this.ModificationChangeValue, this.InitialPrice);
                this.isApplicable = true;
            }
            if (this.ModificationFixedVariable == timeToReservation) {
                this.modifiedPrice = this.GetModifiedPrice(this.ModificationType, this.ModificationChangeValue, this.InitialPrice);
                this.isApplicable = true;
            }
            this.modifiedPrice = Math.Floor(this.modifiedPrice);
        }

        public override double GetPriceForDay(DateTime priceForDay) {
            return this.modifiedPrice;
        }

        public override double GetPriceDiffForDay(DateTime priceForDay) {
            return this.modifiedPrice - this.InitialPrice;
        }

        public override bool ModifierIsApplicable(DateTime priceForDay) {
            return this.isApplicable;
        }

        #endregion

    }
}
